
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<span style="font-size:18px;">
<html>
<head>
    <title>登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="attendance/css/bootstrap.min.css" type="text/css"/>
    <script language="JavaScript" src="attendance/js/jquery.min.js" ></script>
    <script language="JavaScript" src="attendance/js/bootstrap-datetimepicker.js" ></script>

    <style>
        body{
            background: url(attendance/img/logbk.jpg) no-repeat;background-size:cover;font-size: 16px;
        }
    </style>

</head>

<body>

<div class="container" style="margin-top: 260px;">

    <div class="row">

        <div class="col-md-5 col-md-offset-4">

            <div class="panel panel-default">

                <div class="panel-heading text-center">
                    <h3>考勤管理系统</h3>
                </div>
                <div class="panel-body" >
                    <form action="#">

                        <div style="margin-left: 40px">
                            <div class="form-group" >
                            <div class="form-inline">
                                 <label for="" >用户名:&ensp;</label>
                                 <input type="text" class="form-control" id="user_name" placeholder="用户名">
                                 <span id="uname" style="font-size:10px; color: red;"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="form-inline">
                                 <label for="" >密&emsp;码:&ensp;</label>
                                 <input type="password" class="form-control" id="user_password" placeholder="密码">
                                 <span id="upawd" style="font-size:10px; color: red;"></span>
                            </div>
                        </div>

                        <div class="checkbox">

                            <label>
                                <input type="checkbox" name="remeber">记住密码
                            </label>
                        </div>

                        </div>


                        <button type="button" class="btn btn-success btn-block btn-lg" onclick="initDate()">登录</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">

     $(document).keyup(function(event){
         if(event.keyCode ==13){
             initDate();
         }
     });



    function initDate(){
        var uname = $("#user_name").val();
        var upawd = $("#user_password").val();

        if($.isEmptyObject(uname)){
            $("#uname").text("请输入用户名");
            return;
        }else {
            $("#uname").text("");
        }
        if($.isEmptyObject(upawd)){
            $("#upawd").text("请输入密码");
            return;
        }else {
            $("#upawd").text("");
        }

        var postUrl = "${pageContext.request.contextPath}/member/userLogin";
        var urlad = "${pageContext.request.contextPath}/admin";
        var urlus = "${pageContext.request.contextPath}/user";
        var urlth = "${pageContext.request.contextPath}/teacher";

        var str = {
            "userLoginName": uname,
            "userLoginPwd": upawd
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    if (data.msg == "密码错误"){
                        $("#upawd").text("密码错误");
                    }else {
                        $("#uname").text(data.msg);
                    }
                }else {
                    if(data.result.userLevel === "0"){
                        location.href = urlad;
                    }else if (data.result.userLevel === "1"){
                        location.href = urlth;
                    } else if (data.result.userLevel === "2"){
                        location.href = urlus;
                    }
                    sessionStorage.setItem("user",JSON.stringify(data));
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }


</script>


</body>
</html>
</span>